package com.cy.pj.sys.servicelmpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cy.pj.common.bo.PageObject;
import com.cy.pj.common.exception.ServiceException;
import com.cy.pj.sys.dao.SysLogDao;
import com.cy.pj.sys.entity.SysLog;
import com.cy.pj.sys.service.SysLogService;

@Service
public class SysLogServiceImpl implements SysLogService{
	

	@Autowired  //赋值
	private SysLogDao sysLogDao;
	
	@Override
	public PageObject<SysLog> findPageObjects(String username, Integer pageCurrent) {
		
		//1)参数校验
	
		//下面判断不可以颠倒  小于1时抛出异常
		if(pageCurrent==null||pageCurrent<1) 
			throw new IllegalArgumentException("当前页码值不合法");
		
		//查询总记录数,并进行校验--
		int rowCount=sysLogDao.getRowCount(username);
		//2.查询
		if(rowCount==0)
			throw new ServiceException("没有对应记录");//此异常
		//3当前页面
		int pageSize=3;
		//计算当前页查询
		int startIndex=(pageCurrent-1)*pageSize;
		List<SysLog> records =
				sysLogDao.findPageObjecteSysLogs(username, startIndex, pageSize);
		//4.对业务层查询结果进行处理和封装
		//注意PageObject构造方法
		return new PageObject<>(records, rowCount, pageSize, pageCurrent);
	}


	@Override
	public int deleteObjects(Integer... ids) {
		//1.参数校验
		if(ids==null||ids.length==0)
		throw new IllegalArgumentException("参数值无效");
		//2.执行删除操作
		int rows=sysLogDao.deleteObjects(ids);
		//3.验证删除
		if(rows==0)
			throw new ServiceException();
		return 0;
		
	}
}
